/*
* @Author: dengjiayao
* @Date:   2017-08-25 16:02:57
 * @Last Modified by:   dengjiayao
 * @Last Modified time: 2018-03-21 16:39:54
*/

import Vue from 'vue'

const SUCCESS = 1000000
const serverRoot = server.root
const API_ROOT = server.root + '/manage/trade'

const voucherAuditListResource = Vue.resource(API_ROOT + '/getMoneyVoucherAuditList')
export const getVoucherAuditList = ({ dispatch }, params) => {
  return voucherAuditListResource.get(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('VOUCHER_AUDIT_NEED_FRESH', 0)
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}

const auditMoneyVoucherResource = Vue.resource(API_ROOT + '/auditMoneyVoucher')
export const auditMoneyVoucher = ({ dispatch }, params) => {
  return auditMoneyVoucherResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return dispatch('VOUCHER_AUDIT_NEED_FRESH', 1)
    }
    return Promise.reject(res.data)
  })
}

// 新股列表
const newSharesListResource = Vue.resource(serverRoot + '/newmanage/trade/stagging/list')
export const getNewSharesList = ({ dispatch }, params) => {
  return newSharesListResource.get(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('HK_FRESH', 0)
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}

// 新股新建
const saveNewShareResource = Vue.resource(serverRoot + '/newmanage/trade/stagging/save')
export const saveNewShare = ({ dispatch }, params) => {
  return saveNewShareResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return dispatch('HK_FRESH', 1)
    }
    return Promise.reject(res.data)
  })
}

// 新股更新
const updateNewShareResource = Vue.resource(serverRoot + '/newmanage/trade/stagging/update')
export const updateNewShare = ({ dispatch }, params) => {
  return updateNewShareResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return dispatch('HK_FRESH', 1)
    }
    return Promise.reject(res.data)
  })
}

// 新股排序
const swapNewShareResource = Vue.resource(serverRoot + '/newmanage/trade/stagging/swap')
export const swapNewShare = ({ dispatch }, params) => {
  return swapNewShareResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return dispatch('HK_FRESH', 1)
    }
    return Promise.reject(res.data)
  })
}

// 导入打新客户资料
const importNewSharesCustomerResource = Vue.resource(
  serverRoot + '/newmanage/trade/stagging/import'
)
export const importNewSharesCustomer = ({ dispatch }, params) => {
  return importNewSharesCustomerResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return dispatch('HK_FRESH', 1)
    }
    return Promise.reject(res.data)
  })
}

const newShareCustomersResource = Vue.resource(serverRoot + '/newmanage/trade/stagging/user/list')
export const getNewShareCustomers = ({ dispatch }, params) => {
  return newShareCustomersResource.get(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('HK_FRESH', 0)
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}

const updateStatusResource = Vue.resource(
  serverRoot + '/newmanage/trade/stagging/user/updateStatus'
)
export const updateStatus = ({ dispatch }, params) => {
  return updateStatusResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return dispatch('HK_FRESH', 1)
    }
    return Promise.reject(res.data)
  })
}

const saveCustomerResource = Vue.resource(serverRoot + '/newmanage/trade/stagging/user/save')
export const saveCustomer = ({ dispatch }, params) => {
  return saveCustomerResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('HK_FRESH', 1)
      return Promise.resolve(res.data)
    }
    return Promise.reject(res.data)
  })
}

const configSubaccountResource = Vue.resource(API_ROOT + '/configSubaccount')
export const configSubaccount = ({ dispatch }, params) => {
  return configSubaccountResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('HK_FRESH', 1)
      return Promise.resolve(res.data)
    }
    return Promise.reject(res.data)
  })
}

const getSubaccountListResource = Vue.resource(API_ROOT + '/getSubaccountList')
export const getSubaccountList = ({ dispatch }, params) => {
  return getSubaccountListResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      dispatch('HK_FRESH', 0)
      return Promise.resolve(res.data)
    }
    return Promise.reject(res.data)
  })
}
